package csc.com.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;


@WebFilter("/AuthenticationFilter")
public class AuthenticationFilter implements Filter {

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
	    String password=request.getParameter("password");  
	    String username = request.getParameter("userName");
	    
	    if(password.equals("admin123") && username.equals("admin")) {  
	    	RequestDispatcher rd = request.getRequestDispatcher("/adminPage.html");
	    	rd.forward( request, response);
	       
	    }
	     chain.doFilter(request, response);//sends request to next resource  
	}

	@Override
	public void init(FilterConfig config) throws ServletException {
		// TODO Auto-generated method stub
		
	}

}
